package com.x.epspace.message.client;

import java.io.InputStream;
import java.util.Properties;

public class MessageConfig {
	static private String ip;
	static private String dbname;
	static private String dbpassword;
	static private String dbport;
	static private String dbuser;
	static private MessageConfig config;
    static private String configFilename="sms.properties";
    static private String webServiceUrl;
    static private String apicode;
    private static String channel="";
	private static String username_cu="";
	private static String code_cu="";
	private static String password_cu="";
	
	private static String smslimit = "0";
	private static long  smstimer = 0;

	public static String getIp() {
		intial();
		return ip;
	}
	public static String getApicode() {
		intial();
		return apicode;
	}
	public static void setApicode(String apicode) {
		MessageConfig.apicode = apicode;
	}
	public static String getWebServiceUrl() {
		intial();
		return webServiceUrl;
	}
	public static String getDbname() {
		intial();
		return dbname;
	}
	public static String getDbpassword() {
		intial();
		return dbpassword;
	}
	public static String getDbport() {
		intial();
		return dbport;
	}
	public static String getDbuser() {
		intial();
		return dbuser;
	}
	public static MessageConfig getConfig() {
		return config;
	}
	private MessageConfig() throws Exception{
		Properties prop = new Properties();
		ClassLoader classLoader = Thread.currentThread()
				.getContextClassLoader();
		InputStream is = classLoader.getResourceAsStream(configFilename);
		prop.load(is);
		ip=prop.getProperty("ip");
		dbname=prop.getProperty("dbname");
		dbpassword=prop.getProperty("dbpassword");
		dbport=prop.getProperty("dbport");
		dbuser=prop.getProperty("dbuser");
		webServiceUrl=prop.getProperty("webServiceUrl");
		apicode=prop.getProperty("apicode");
		channel=prop.getProperty("channel");
		username_cu=prop.getProperty("username_cu");
		code_cu=prop.getProperty("code_cu");
		password_cu=prop.getProperty("password_cu");
		smslimit = prop.getProperty("smslimit");
		smstimer = Long.parseLong(prop.getProperty("smstimer"));
	}
	
	public static String getchannel(){
		intial();
		return channel;
	}
	public static String getUsername_cu() {
		intial();
		return username_cu;
	}
	public static void setUsername_cu(String username_cu) {
		intial();
		MessageConfig.username_cu = username_cu;
	}
	public static String getCode_cu() {
		intial();
		return code_cu;
	}
	public static void setCode_cu(String code_cu) {
		intial();
		MessageConfig.code_cu = code_cu;
	}
	public static String getPassword_cu() {
		intial();
		return password_cu;
	}
	public static void setPassword_cu(String password_cu) {
		intial();
		MessageConfig.password_cu = password_cu;
	}
	
	
	public static String getSmslimit() {
		intial();
		return smslimit;
	}
	public static void setSmslimit(String smslimit) {
		intial();
		MessageConfig.smslimit = smslimit;
	}
	public static long getSmstimer() {
		intial();
		return smstimer;
	}
	public static void setSmstimer(long smstimer) {
		intial();
		MessageConfig.smstimer = smstimer;
	}
	
	static private  void intial(){
		if(config==null){
			try{
				config=new MessageConfig();
			}catch(Exception e){
				e.printStackTrace();
			}
		}
	}

}
